package com.sky.controller.user;

import com.sky.dto.shopping.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.User.ShoppingCart.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 褚金龙
 * @Date 2024/9/24 15:30
 */
@CrossOrigin("*")
@RestController("UserShoppingCartController")
@RequestMapping("/user")
@Api(tags = "C端购物车相关接口")
@Slf4j
public class ShoppingCartController {
      @Autowired
      private ShoppingCartService shoppingCartService;
    @PostMapping("/shoppingCart/add")
    @ApiOperation("添加购物车")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
          log.info("shoppingCartDTO{}",shoppingCartDTO);
         shoppingCartService.addShoppingCart(shoppingCartDTO);
        return Result.success();
    }


    @GetMapping("/shoppingCart/list")
    @ApiOperation("查看购物车")
    public Result<List<ShoppingCart>> list(){

       List<ShoppingCart> list= shoppingCartService.queryShoppingCart();
        return Result.success(list);
    }


    @GetMapping("/shoppingCart/{count}")
    @ApiOperation("修改购物车商品数量")
    public Result count(@PathVariable Integer count,Long id){
        log.info("count{}id{}",count,id);
      shoppingCartService.updateCount(count,id);
        return Result.success();
    }


    @DeleteMapping("/shoppingCart/clean")
    @ApiOperation("清空购物车")
    public Result deleteCart(){

        shoppingCartService.deleteCart();
        return Result.success("ok");
    }
}
